package com.xyh.mapper;

import com.xyh.entity.YxcUser;
import org.apache.ibatis.annotations.*;

@Mapper
public interface YxcUserMapper {

    @Select("select * from yxc_user where telephone = #{login_telephone} and flag = 1")
    YxcUser selectByTelephone(@Param("login_telephone") String login_telephone);

    @Update("update yxc_user set password = #{password} , user_name = #{user_name} , user_age = #{user_age} , user_birth = #{user_birth} , user_address = #{user_address} , state = 1 where telephone = #{telephone}")
    int updateYxcUser(YxcUser yxcUser);

    @Insert("insert into yxc_user(telephone,password) values(#{login_telephone},#{login_password})")
    int insertNewUser(@Param("login_telephone") String login_telephone,@Param("login_password") String login_password);

    @Update("update yxc_user set yhq = (select yhq from (select yhq from yxc_user where telephone = #{telephone}) as tmp) - 1 \n" +
            "\t where telephone = '18258494608'")
    int updateYhqByPhone(@Param("telephone") String owner_telephone);

    @Update("update yxc_user set xiaofei = (select xiaofei from (select xiaofei from yxc_user where telephone = '18258494608') as tmp1) + #{xiaofei} , \n " +
            "\t  jifen = (select jifen from (select jifen from yxc_user where telephone = #{telephone}) as tmp2) + #{xiaofei} \n " +
            "\t\t  where telephone = #{telephone}")
    int updateXiaofeiByPhone(@Param("telephone") String owner_telephone,@Param("xiaofei") int xiaofei);

    @Update("UPDATE yxc_user set jifen = ( \n" +
            "\t SELECT jifen FROM ( \n" +
            "\t\t SELECT jifen FROM yxc_user where telephone = #{telephone} and flag = 1) as tmp  ) - #{jifen_jian} , \n" +
            "\t\t\t\t\t\t\t\t\t\t yhq = ( \n" +
            "\t SELECT yhq FROM ( \n" +
            "\t\t SELECT yhq FROM yxc_user where telephone = #{telephone} and flag = 1) as tmp  ) + #{yhq_add} \n" +
            "\t\t where telephone = #{telephone} and flag = 1")
    int updateJifenAndYhqByPhone(@Param("telephone") String telephone,@Param("jifen_jian") int jifen_jian,@Param("yhq_add") int yhq_add);
}
